package com.sqkj.service;

import com.sqkj.dao.UserCardDao;
import com.sqkj.dao.UserDao;
import com.sqkj.entity.User;
import com.sqkj.entity.UserCard;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserCardService {
    @Resource
    UserCardDao dao;
    public List<UserCard> findAll() {
        return dao.findAll();
    }
    public UserCard findById(int id) {
        return dao.findById(id);
    }
    public List<UserCard> findByUserId(int userId) {
        List<UserCard> userCards = null;
        if ((userCards = dao.findByUserId(userId)).size() == 0) {
            return userCards;
        } else {
            return userCards;
        }

    }
    @Transactional
    public Boolean deleteById(int id){
        if (dao.deleteById(id)>0){
            return true;
        }else {
            return false;
        }
    }
    @Transactional
    public Boolean add(UserCard userCard) {
        if (dao.add(userCard.getUserId(),userCard.getJob(),userCard.getPhone(),userCard.getEmail(),userCard.getComName(),userCard.getUsComName(),userCard.getComInfo(),userCard.getAddress(),userCard.getType(),userCard.getTag(),userCard.getUserCardIcon())>0){
            return true;
        }else {
            return false;
        }
    }
}
